<template>
  <div>
    <div v-if="xmck">
      <el-row>
        <el-button type="primary" @click="toprojectadd" plain>新增</el-button>
        <el-button type="primary" plain>修改</el-button>
        <el-button type="primary" plain>删除</el-button>
        <el-button type="primary" plain>导入</el-button>
        <el-button type="primary" plain>导出</el-button>
        <br /><br />
      </el-row>
      <!-- #07c4a8 -->
      <hr style="background-color: #07c4a8; height: 1px; border: none" />
      <br />

      <el-form :inline="true" :model="projectinfoForm" class="demo-form-inline">
        <el-form-item label="项目名称">
          <input type="hidden" v-model="projectinfoForm.pId" />
          <el-input
            v-model="projectinfoForm.projectName"
            placeholder="项目名称"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="dj"
            ></el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="填报人">
          <el-input v-model="projectinfoForm.name" placeholder="填报人">
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="dj"
            ></el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="项目状态">
          <el-select
            v-model="projectinfoForm.projectStatus"
            placeholder="项目状态"
          >
            <el-option label="全部" value=""></el-option>
            <el-option label="信息立项" value="信息立项"></el-option>
            <el-option label="资格审查" value="资格审查"></el-option>
            <el-option label="放弃" value="放弃"></el-option>
            <el-option label="竣工" value="竣工"></el-option>
            <el-option label="中标" value="中标"></el-option>
            <el-option label="投标" value="投标"></el-option>
            <el-option label="落标" value="落标"></el-option>
            <el-option label="立项分析" value="立项分析"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getstu">查询</el-button>
        </el-form-item>
      </el-form>

      <center>
        <h2>项目状态变更</h2>
      </center>
      <el-table :data="projects" border style="width: 100%">
        <!-- <template scope="scope">
          <el-radio
            :label="scope.$index"
            v-model="currentRow"
            @change.native="getCurrentRow(scope.row)"
            style="color: #fff; padding-left: 10px; margin-right: -25px"
          ></el-radio>
        </template> -->

        <el-table-column label="" width="50">
          <template scope="scope">
            <el-radio
              :label="scope.$index"
              v-model="radio"
              @change.native="getCurrentRow(scope.$index, scope.row)"
              >{{&nbsp;}}</el-radio
            >
          </template>
        </el-table-column>

        <el-table-column
          type="index"
          label="序号"
          width="50"
          :index="indexMethod"
        >
        </el-table-column>
        <el-table-column prop="sid" label="ID" width="180" v-if="yc">
        </el-table-column>
        <el-table-column prop="projectName" label="项目名称"> </el-table-column>
        <el-table-column prop="projectStatus" label="项目状态">
        </el-table-column>
        <el-table-column prop="name" label="填报人"> </el-table-column>
        <el-table-column prop="presentTime" label="当前时间"> </el-table-column>

        <el-table-column fixed="right" label="操作" width="150">
          <template slot-scope="scope">
            <el-dropdown @command="cao" szie="small">
              <el-button type="primary" size="small">
                操作<i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                  :command="{ sid: scope.row.sid, type: '修改' }"
                  @click="toprojectup(scope.row)"
                  >修改</el-dropdown-item
                >
                <el-dropdown-item
                  :command="{ sid: scope.row.sid, type: '删除' }"
                  >删除</el-dropdown-item
                >
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <project-status-add
      v-if="xmadd"
      @toback="toback"
      @addprojects="addprojects"
    ></project-status-add>
    <project-status-update
      v-if="xmup"
      :projectschange="projectschanges"
      @toback="toback"
    ></project-status-update>

    <el-dialog title="提示" :visible.sync="dialogVisible" width="70%">
      <project-info-list
        v-if="dialogVisible"
        @row="project"
      ></project-info-list>
    </el-dialog>
  </div>
</template>

<script>
import ProjectStatus from "../../model/zy/ProjectStatusChange.js";
import ProjectStatusAdd from "../zy/ProjectStatusAdd";
import ProjectStatusUpdate from "../zy/ProjectStatusUpdate";
import ProjectInfoList from "../common/projectInfo/ProjectInfoList.vue";

const pjs = new ProjectStatus();

export default {
  components: { ProjectStatusAdd, ProjectStatusUpdate, ProjectInfoList },
  data() {
    return {
      projects: [],
      projectinfoForm: {
        projectName: "",
        name: "",
        projectStatus: "",
      },
      yc: null,
      currentRow: 0,
      xmck: true,
      xmadd: false,
      xmup: false,
      dialogVisible: false,
      projectschanges: [],
      radio: "",
    };
  },
  methods: {
    //全局查询----this.projectinfoForm
    getstu() {
      pjs.getProject(this.projectinfoForm).then((response) => {
        this.projects = response.data;
      });
    },

    //响应项目组件
    project(row) {
      this.projectinfoForm.projectName = row.projectName;
      this.projectinfoForm.pId = row.id; //获取所属项目id
      this.dialogVisible = false;
    },

    //单选
    getCurrentRow(index, row) {
      console.log(row.sid);
    },

    //序号自增
    indexMethod(index) {
      return index + 1;
    },

    //下拉菜单
    cao(command) {
      if (command.type == "修改") {
        this.toprojectup(command);
      }
      if (command.type == "删除") {
        //调用删除方法
        this.delBtn(command);
      }
    },

    //删除
    delBtn(row) {
      pjs.Delstatus(row.sid).then(() => {
        this.getstu();
      });
    },

    //修改
    toprojectup(row) {
      pjs.getByid(row.sid).then((response) => {
        console.log(row.sid);
        this.projectschanges = response.data;
      });
      this.xmck = false;
      this.xmadd = false;
      this.xmup = true;
    },

    //添加
    toprojectadd() {
      this.xmck = false;
      this.xmadd = true;
      this.xmup = false;
    },

    toback() {
      this.getstu();
      this.xmck = true;
      this.xmadd = false;
      this.xmup = false;
    },

    dj() {
      this.dialogVisible = true;
    },

    //添加
    addprojects(projectstatusadd) {
      pjs.Addpsc(projectstatusadd).then(() => {
        this.xmck = true;
        this.xmadd = false;
        this.xmup = false;
        this.getstu();
      });
    },
  },
  created() {
    this.getstu();
  },
};
</script>

<style>
</style>